﻿namespace org.webguvenligi.NSecureImageLib.GraphicFileFormats.Utilities
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Reflection;

    public static class HelperUtilities
    {
        public static string ToString(object sourceObject)
        {
            StringBuilder toStringWriter = new StringBuilder();
            if (sourceObject != null)
            {
                Type currentType = sourceObject.GetType();
                System.Reflection.PropertyInfo[] wholeProperties =
                    currentType.GetProperties();
                toStringWriter.AppendLine(currentType.Name);
                toStringWriter.AppendLine("-----------------------------------------");
                foreach (PropertyInfo tempProp in wholeProperties)
                {
                    object valueObject = tempProp.GetValue(sourceObject, null);
                    if (valueObject == null)
                        valueObject = String.Empty;
                    toStringWriter.AppendFormat("{0}: {1}\r\n", tempProp.Name, valueObject.ToString());
                }
                toStringWriter.AppendLine("-----------------------------------------");
            }
            return toStringWriter.ToString();
        }
    }
}
